package com.imodia.checkoo.lucence.make;

import java.util.List;

import com.hsq.commons.util.db.PageResult;
import com.hsq.commons.util.db.SqlParam;
import com.imodia.checkoo.bean.CmsArticleBean;
import com.imodia.checkoo.lucence.LucenceDataBean;
import com.imodia.checkoo.service.CmsArticleService;

public class NewsMkLucenceFile extends MakeLucenceFile{
	
	private CmsArticleService cmsArticleService;

	public void setCmsArticleService(CmsArticleService cmsArticleService) {
		this.cmsArticleService = cmsArticleService;
	}

	@Override
	public int loadData(int id,int currentPage,List<LucenceDataBean> list) {
		
		SqlParam sql = new SqlParam();
		if(id>0){
			sql.andEqualTo("id", String.valueOf(id));
		}
		sql.setCurrentPage(currentPage);
		sql.setPageSize(500);
		PageResult<CmsArticleBean> page = cmsArticleService.page(sql);
		List<CmsArticleBean> newsList = page.getData();
		for(int i=0;i<newsList.size();i++){
			CmsArticleBean obj = newsList.get(i);
			obj.setIsHtml(1);
			obj.setPageId(12);
			LucenceDataBean data = new LucenceDataBean();
			data.setId(String.valueOf(obj.getId()));
			data.setTitle(obj.getTitle());
			data.setKeyWord(obj.getTitle()+obj.getShortContent());
			data.setShortDesc(obj.getShortContent());
			data.setAddress("");
			data.setDocumentId(String.valueOf(obj.getDocumentId()));
			data.setHrefUrl(obj.getHrefUrl());
			data.setContent(obj.getContent());
			data.setHit(String.valueOf(obj.getHit()));
			
			data.setDynamicUrl(obj.getDynamicUrl());
			
			data.setIsValid(String.valueOf(obj.getIsValidate()));
			data.setExt1(obj.getExt1());
			data.setExt2(obj.getExt2());
			data.setExt3(obj.getExt3());
			data.setExt4(obj.getExt4());
			data.setExt5(obj.getExt5());
			data.setExt6(obj.getExt6());
			data.setExt7(obj.getExt7());
			data.setExt8(obj.getExt8());
			data.setExt9(obj.getExt9());
			data.setExt10(obj.getExt10());
			data.setExt11(obj.getExt11());
			data.setExt12(obj.getExt12());
			data.setExt13(obj.getExt13());
			data.setExt14(obj.getExt14());
			data.setExt15(obj.getExt15());
			data.setExt16(obj.getExt16());
			data.setExt17(obj.getExt17());
			data.setExt18(obj.getExt18());
			data.setExt19(obj.getExt19());
			data.setExt20(obj.getExt20());
			
			list.add(data);			
		}
		
		if(page.getPages()>=(page.getCurrentPage()+1)){
			return currentPage+1;
		}
		return 0;
	}

	

}
